package com.wangsh.forward.outer.service.impl;

import java.io.File;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wangsh.forward.outer.service.IServerOperOuterService;
import com.wangsh.forward.system.pojo.ASysHistory;
import com.wangsh.forward.system.pojo.ASysHistoryEnum;
import com.wangsh.forward.system.service.ISystemService;
import com.wangsh.forward.system.service.impl.SystemServiceImpl;
import com.wangsh.forward.util.ServiceCallableUtil;
import com.wangsh.webforward.common.pojo.ApiResponse;
import com.wangsh.webforward.common.service.BaseServiceImpl;
import com.wangsh.webforward.common.util.ConstatFinalUtil;
import com.wangsh.webforward.common.util.ExecutorServiceUtil;

/**
 * Oper批量请求
 * 
 * @author wangsh
 * @param <T>
 */
public class ServerOperOuterServiceImpl extends BaseServiceImpl implements IServerOperOuterService
{
	/* 持有systemService的对象 */
	private ISystemService systemService = new SystemServiceImpl();
	
	@Override
	public void requestMultiThreadService(JSONObject dataReqJSON, int stRecord, int edRecord)
	{
		ConstatFinalUtil.SYS_LOGGER.info("requestMultiThreadService;stRecord:{},edRecord:{}", stRecord, edRecord);

		/* 接收参数 */
		JSONObject dataResJSON = new JSONObject();
		String url = dataReqJSON.get("url") + "";
		JSONArray headerArr = (JSONArray) dataReqJSON.get("header");
		JSONArray requestArr = (JSONArray) dataReqJSON.get("request");
		String method = dataReqJSON.get("method") + "";
		String sn = dataReqJSON.get("sn") + "";

		/* 响应内容 */
		Map<String, String> responseMap = new HashMap<String, String>();

		/* 次数统计 */
		int totalCount = 0;
		int succedCount = 0;
		int failedCount = 0;

		/* 随机获取 */
		Random random = new Random();
		String responseResult = "";
		Map<String, String> responseResultMap = new HashMap<String, String>();
		/* 多线程请求 */
		for (int i = stRecord; i <= edRecord; i++)
		{
			/* 请求头随机, */
			JSONObject headerJSON = new JSONObject();
			if (headerArr.size() > 0)
			{
				headerJSON = headerArr.getJSONObject(random.nextInt(headerArr.size()));
			}
			Map<String, String> headerMap = ConstatFinalUtil.jsonToMap(headerJSON);
			/* 请求体随机 */
			JSONObject requestJSON = new JSONObject();
			if (requestArr.size() > 0)
			{
				requestJSON = requestArr.getJSONObject(random.nextInt(requestArr.size()));
			}
			Map<String, String> paramsMap = ConstatFinalUtil.jsonToMap(requestJSON);

			String response = "";
			if ("post".equalsIgnoreCase(method))
			{
				response = this.httpUtil.methodPost(url, headerMap, paramsMap, responseMap);
			} else
			{
				response = this.httpUtil.methodGet(url, headerMap, paramsMap, responseMap);
			}

			if (!"".equalsIgnoreCase(response))
			{
				/* 存储结果 */
				if ("".equalsIgnoreCase(responseResult))
				{
					responseResult = response;
					responseResultMap = responseMap;
				}
				succedCount++;
			} else
			{
				failedCount++;
			}
			totalCount++;
		}

		/* 存储结果体 */
		JSONObject responseHeaderJSON = new JSONObject();
		responseHeaderJSON.putAll(responseResultMap);

		dataResJSON.put("totalCount", totalCount);
		dataResJSON.put("succedCount", succedCount);
		dataResJSON.put("failedCount", failedCount);
		dataResJSON.put("response", responseResult);
		dataResJSON.put("responseHeader", responseHeaderJSON);

		dataResJSON.put("sn", sn);
		ConstatFinalUtil.SYS_LOGGER.info("请求结果:{}", dataResJSON.toJSONString());

		// TODO 执行完成以后,需要计算请求的结果,需要上报给请求的网址
		String notifyUrl = dataReqJSON.getString("notifyUrl");
		if (notifyUrl != null && !"".equalsIgnoreCase(notifyUrl))
		{
			/* 按照上行的信息去请求 */
			JSONObject dataCliReqJSON = new JSONObject();
			dataCliReqJSON.put("version", "1");
			dataCliReqJSON.put("method", "aa");
			dataCliReqJSON.put("pubKey", "1");
			dataCliReqJSON.put("encrypt", "1");
			dataCliReqJSON.put("data", dataResJSON);

			/* 请求体 */
			Map<String, String> paramsCliReqMap = new HashMap<String, String>();
			paramsCliReqMap.put("json", dataCliReqJSON.toJSONString());
			while (true)
			{
				String response = this.httpUtil.methodPost(notifyUrl, Collections.EMPTY_MAP, paramsCliReqMap,
						responseMap);
				JSONObject responseJSON = (JSONObject) JSON.parse(response);
				if (responseJSON != null && "0".equalsIgnoreCase(responseJSON.getString("code")))
				{
					ConstatFinalUtil.SYS_LOGGER.info("请求结束:{}", dataResJSON.toJSONString());
					break;
				}
			}
		}
	}

	@Override
	public JSONObject uploadOrdersUser(HttpServletRequest request)
	{
		ConstatFinalUtil.SYS_LOGGER.info("==uploadOrdersUser==");
		// 存储历史文件相关信息
		JSONObject historyFileInfo = new JSONObject();

		String filePath = "";
		// 1.判断是否是文件上传表单
		if (ServletFileUpload.isMultipartContent(request))
		{
			// 2.创建文件元素工厂
			DiskFileItemFactory factory = new DiskFileItemFactory();
			// 3.创建文件上传对象
			ServletFileUpload sfu = new ServletFileUpload(factory);
			try
			{
				// 4.获取所有FileItem对象
				List<FileItem> items = sfu.parseRequest(request);
				//
				JSONObject jsonObPa = new JSONObject();
				for (FileItem item : items)
				{
					// 5.判断是文字字段还是文件字段
					if (item.isFormField())
					{
						// 文字字段
						// System.out.println("文件参数" + item.getFieldName() + "----" + item.getString());
						jsonObPa.put(item.getFieldName(), item.getString());
					} else
					{
						// 文件字段
						// System.out.println("文件名:" + item.getName());
						// System.out.println("文件大小:" + item.getSize());
						// System.out.println("文件类型:" + item.getContentType());
						// System.out.println("文件内容:"+item.getString());
						String truePath = ConstatFinalUtil.CONFIG_JSON.getString("website.truePath");
						/* tomcat系统的配置 */
						JSONObject pathTomcatJSON = ConstatFinalUtil.SYS_PRO_MAP.get("path.tomcat") ;
						if(pathTomcatJSON != null)
						{
							/* 获取Tomcat的根路径 */
							truePath = pathTomcatJSON.getString("value") + "/webapps/"; 
						}
						// 保存文件
						String relaPath = ConstatFinalUtil.CONFIG_JSON.getString("website.uploadFile") + "/csv/";
						File file = new File(truePath + relaPath);
						// 判断文件夹是否存在，不存在就创建
						if (!file.exists())
						{
							// System.out.println("文件夹以创建");
							file.mkdirs();
						} else
						{
							// System.out.println("文件夹已存在");
						}
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						String dateStr = sdf.format(new Date());
						// 获取文件后缀
						String houzhui = item.getName().split("\\.")[1];
						String uuidName = UUID.randomUUID()+"";
						// 文件名称
						String fileName =  uuidName+ "." + houzhui;
						filePath = relaPath + "/" + fileName;
						String path = truePath + filePath;
						historyFileInfo.put("path", truePath + filePath);
						historyFileInfo.put("relaPath", filePath);
						historyFileInfo.put("updateTime", dateStr);
						historyFileInfo.put("name",uuidName);
						historyFileInfo.put("oldName", item.getName());
						historyFileInfo.put("json", jsonObPa);
						// 进入到文件上传代表这个文件状态为正在处理,0:正在处理，1:处理完成
						historyFileInfo.put("status", "0");
						// System.out.println(filePath);
						// 写文件
						item.write(new File(path));
					}
				}
			} catch (FileUploadException e)
			{
				// e.printStackTrace();
			} catch (Exception e)
			{
				/// e.printStackTrace();
			}
		}
		return historyFileInfo;
	}

	@Override
	public String writeFileCsv(String path, Map<String, List<String>> dataInfoMap)
	{
		// String path2 = "C:\\Users\\Administrator\\Desktop\\aa.csv";
		List<Map<String, String>> readFileCsv = poiUtil.readFileCsv(path);

		List<String> codeList = dataInfoMap.get("code");
		List<String> infoList = dataInfoMap.get("info");
		List<String> cookieFiniList = dataInfoMap.get("cookieFini");
		List<String> ipList = dataInfoMap.get("ip");
		
		List<String> friendNumList = dataInfoMap.get("friendNum");
		List<String> phoneResList = dataInfoMap.get("phoneRes");
		List<String> birthdayList = dataInfoMap.get("birthday");
		List<String> majorList = dataInfoMap.get("majorList");
		List<String> adverList = dataInfoMap.get("adverList");
		List<String> usersTypeList = dataInfoMap.get("usersTypeList");
		
		// 原来文件内容的头部信息
		List<String> header = new ArrayList<String>();
		if (readFileCsv.size() == 0)
		{
			return path;
		}
		for (Entry<String, String> entry : readFileCsv.get(0).entrySet())
		{
			header.add(entry.getKey());
		}
		// 返回结果列
		header.add("ip");
		header.add("code");
		header.add("result");
		header.add("好友数");
		header.add("手机号(最终)");
		header.add("生日");
		header.add("专业");
		header.add("广告");
		header.add("用户类型");
		header.add("cookieFini");
		// 原来的内容信息
		List<List<String>> listNum = new ArrayList<List<String>>();
		// 总共的列数
		for (int i = 0; i < readFileCsv.size(); i++)
		{
			Map<String, String> map = readFileCsv.get(i);
			List<String> list = new ArrayList<String>();
			// 某行的X个值
			for (Entry<String, String> entry : map.entrySet())
			{
				list.add(entry.getValue());
			}
			if (i <= ipList.size() - 1)
			{
				// 放入每一行对应的返回信息码,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(ipList.get(i));
			}
			if (i <= codeList.size() - 1)
			{
				// 放入每一行对应的返回信息码,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(codeList.get(i));
			}
			if (i <= infoList.size() - 1)
			{
				// 放入每一行对应的返回信息,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(infoList.get(i));
			}
			if (i <= friendNumList.size() - 1)
			{
				// 放入每一行对应的返回信息,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(friendNumList.get(i));
			}
			if (i <= phoneResList.size() - 1)
			{
				// 放入每一行对应的返回信息,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(phoneResList.get(i));
			}
			if (i <= birthdayList.size() - 1)
			{
				// 放入每一行对应的返回信息,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(birthdayList.get(i));
			}
			if (i <= majorList.size() - 1)
			{
				// 放入每一行对应的返回信息,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(majorList.get(i));
			}
			if (i <= adverList.size() - 1)
			{
				// 放入每一行对应的返回信息,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(adverList.get(i));
			}
			if (i <= usersTypeList.size() - 1)
			{
				// 放入每一行对应的返回信息,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(usersTypeList.get(i));
			}
			if (i <= cookieFiniList.size() - 1)
			{
				// 放入每一行对应的返回信息,每执行一次都会存一次所以应该不会出现多了或者少了的情况出现
				list.add(cookieFiniList.get(i));
			}

			listNum.add(list);
		}
		poiUtil.writeFileCsv(path, header, listNum);
		return path;
	}

	@Override
	public String fwInterfice(List<Map<String, String>> csvContentList, JSONObject uploadData)
	{
		// 获取切换ip的数据
		JSONObject jsonParameter = uploadData.getJSONObject("json");
		int switchNum = jsonParameter.getInteger("switchNum");
		/*
		 * 0:表示手动切换, 1:自动切换
		 */
		int ipSwitchType = jsonParameter.getIntValue("ipSwitchType");
		String engName = jsonParameter.getString("country");
		String path = uploadData.getString("path");
		Map<String, String> headerIpMap = new HashMap<String, String>();

		String country_id = "";
		if (ipSwitchType == 1)
		{
			// 获取当前ip所属国家
			JSONObject ipLocation = this.jsoupUtil.ipLocation("", headerIpMap);
			if (ipLocation != null)
			{
				// 获取当前ip所属的国家英文
				country_id = ipLocation.getJSONObject("data").getString("country_id");
			}
			// 第一次进入就得切换一次ip,切换成用户选择的ip
			boolean switchIp = callCommandUtil.switchIp(null, engName);
			// JSONObject ipLocation2 = this.jsoupUtil.ipLocation("", headerIpMap);
			// System.out.println(ipLocation2);
			// System.out.println(switchIp);
		}
		/* 请求服务器的数据 */
		JSONArray dataRequestArr = new JSONArray();

		/*----------就是为了获取Cookie--------*/
		// 存储 info和code信息用来写入csv文件
		Map<String, List<String>> dataInfoMap = new HashMap<String, List<String>>();
		// 存储info信息
		List<String> infoList = new ArrayList<String>();
		// 存储code信息
		List<String> codeList = new ArrayList<String>();
		/* 存储最终的Cookie */
		List<String> cookieFiniList = new ArrayList<String>();
		/* 存储最终的ip */
		List<String> ipList = new ArrayList<String>();
		/* 手机号 */
		List<String> phoneList = new ArrayList<String>();
		/* 生日 */
		List<String> birthdayList = new ArrayList<String>();
		/* 好友数 */
		List<String> friendNumList = new ArrayList<String>();
		/* 专业 */
		List<String> majorList = new ArrayList<String>();
		/* 广告 */
		List<String> adverList = new ArrayList<String>();
		/* 类型:
		 * 大黑：无专页，无广告
			专业：有专页，无广告
			广告：有专页，有广告
		 *  */
		List<String> usersTypeList = new ArrayList<String>();
		//当前册数,用来判断切换ip
		int currentNum = 0;
		int totalNum = csvContentList.size() ; 
		/* faceBook方法需要的请求头 */
		JSONObject reqJSON = new JSONObject();
		for (Map<String, String> csvContentMap : csvContentList)
		{
			JSONObject requestTempJSON = new JSONObject();
			/* 从CSV中获取信息 */
			String email = csvContentMap.get("email");
			String phone = csvContentMap.get("phone");
			String password = csvContentMap.get("password");
			/* 文档中存储的Cookie */
			String cookieSource = csvContentMap.get("cookie");
			
			reqJSON.clear();
			reqJSON.put("email", email);
			reqJSON.put("phone", phone);
			reqJSON.put("password", password);
			reqJSON.put("cookieSource", cookieSource);
			
			/* 请求体的数据 */
			requestTempJSON.put("email", email);
			requestTempJSON.put("phone", phone);
			requestTempJSON.put("password", password);
			requestTempJSON.put("cookieSource", cookieSource);
			
			/* 调用全部方法 */
			JSONObject resultTempJSON = this.faceBookUtil.all(reqJSON);
			/*=====csv中需要的数据=====*/
			/* json数组,饼干插件需要 */
			String cookieFini = "";
			/* 最终的Cookie,请求头需要 */
			String cookieTarget = "" ; 
			/* ip:请求时的ip */
			String ip = "" ; 
			/* 用户的Id */
			String usersId = "";
			/* 存储目标的手机号 */
			String phoneRes = "" ; 
			/* 生日 */
			String birthday = "" ; 
			String friendNum = "" ; 
			String major = "" ; 
			String adver = "" ; 
			String usersType = "" ; 
			
			/* 相关的链接 */
			String perMainHref = "" ; 
			String aboutHref = "" ; 
			if(resultTempJSON.get("data") != null)
			{
				JSONObject dataTempJSON = (JSONObject) resultTempJSON.get("data");
				
				/* 存储最终的Cookie */
				cookieFini = dataTempJSON.getString("cookieFini");
				cookieTarget = dataTempJSON.getString("cookieTarget");
				ip = dataTempJSON.getString("ip");
				usersId = dataTempJSON.getString("usersId");
				usersId = dataTempJSON.getString("usersId");
				phoneRes = dataTempJSON.getString("phone");
				birthday = dataTempJSON.getString("birthday");
				friendNum = dataTempJSON.getString("friendNum");
				major = dataTempJSON.getString("major");
				adver = dataTempJSON.getString("adver");
				usersType = dataTempJSON.getString("usersType");
				
				perMainHref = dataTempJSON.getString("perMainHref");
				aboutHref = dataTempJSON.getString("aboutHref");
			}
			
			/* 响应码 */
			codeList.add(resultTempJSON.get("code") + "");
			/* 响应信息 */
			infoList.add(resultTempJSON.get("info") + "");
			/* 存储结果到csv */
			cookieFiniList.add(cookieFini);
			ipList.add(ip);
			phoneList.add(phoneRes);
			birthdayList.add(birthday);
			friendNumList.add(friendNum);
			majorList.add(major);
			adverList.add(adver);
			usersTypeList.add(usersType);
			
			/* =====上报数据到服务器===== */
			requestTempJSON.put("responseCode", resultTempJSON.get("code"));
			requestTempJSON.put("responseInfo", resultTempJSON.get("info"));
			requestTempJSON.put("cookieFini", cookieFini);
			requestTempJSON.put("cookieTarget", cookieTarget);
			requestTempJSON.put("ip", ip);
			requestTempJSON.put("usersId", usersId);
			requestTempJSON.put("phoneRes", phone);
			requestTempJSON.put("birthday", birthday);
			requestTempJSON.put("friendNum", friendNum);
			requestTempJSON.put("major", major);
			requestTempJSON.put("adver", adver);
			requestTempJSON.put("usersType", usersType);
			
			requestTempJSON.put("perMainHref", perMainHref);
			requestTempJSON.put("aboutHref", aboutHref);
			/* 上报数据 */
			dataRequestArr.add(requestTempJSON);
			
			currentNum++;
			if (ipSwitchType == 1)
			{
				// 如果switchNum不等于0并且当前ip所属的国家与用户想进的国家不同就切换ip
				if (switchNum != 0 && !country_id.equals(engName))
				{
					if (currentNum % switchNum == 0)
					{
						callCommandUtil.switchIp(null, engName);
					}
				}
			}
			/* 每隔5条,请求一次服务器 */
			if (currentNum % 2  == 0)
			{
				//判断是否访问了faceBook
				/* 多线程启动 */
				ServiceCallableUtil serviceCallableUtil = new ServiceCallableUtil();
				String operType = "requestFaceBookResult" ; 
				Map<String, Object> paramsMap = new HashMap<String, Object>();
				paramsMap.put("totalNum", totalNum);
				paramsMap.put("currentNum", currentNum);
				paramsMap.put("dataRequestArr", dataRequestArr);
				paramsMap.put("serverOperOuterService", this);
				/* 设置参数 */
				serviceCallableUtil.setOperType(operType);
				serviceCallableUtil.setParamsMap(paramsMap);
				
				/* 启动多线程 */
				ExecutorServiceUtil.submit(serviceCallableUtil);
				
				//this.requestFaceBookResult(totalNum,currentNum,dataRequestArr);
			}

		}
		//for循环结束,代表测试完了
		Map<String , Object> condMap = new HashMap<String, Object>();
		condMap.put("name", uploadData.getString("name"));
		ApiResponse<ASysHistory> history = systemService.findOneHistoryService(condMap);
		ASysHistory dataOneJava = history.getDataOneJava();
		dataOneJava.setStatus(ASysHistoryEnum.STATUS_ENABLE.getStatus());
		ApiResponse<Object> sysHistoryResponse = systemService.updateOneHistoryService(dataOneJava);
		ConstatFinalUtil.SYS_LOGGER.info("更新历史文件状态:{}",sysHistoryResponse.toJSON().toJSONString());
		dataInfoMap.put("code", codeList);
		dataInfoMap.put("info", infoList);
		dataInfoMap.put("cookieFini", cookieFiniList);
		dataInfoMap.put("ip", ipList);
		dataInfoMap.put("friendNum", friendNumList);
		dataInfoMap.put("phoneRes", phoneList);
		dataInfoMap.put("birthday", birthdayList);
		dataInfoMap.put("majorList", majorList);
		dataInfoMap.put("adverList", adverList);
		dataInfoMap.put("usersTypeList", usersTypeList);
		// 返回结果之后写入到原先的csv文件中
		writeFileCsv(path, dataInfoMap);
		// 如果等于true代表访问faceBook成功了然后就给返回服务器的json添加数据
		/* 向服务器请求,把结果上传 */
		/* 多线程启动 */
		ServiceCallableUtil serviceCallableUtil = new ServiceCallableUtil();
		String operType = "requestFaceBookResult" ; 
		Map<String, Object> paramsMap = new HashMap<String, Object>();
		paramsMap.put("totalNum", totalNum);
		paramsMap.put("currentNum", currentNum);
		paramsMap.put("dataRequestArr", dataRequestArr);
		paramsMap.put("serverOperOuterService", this);
		/* 设置参数 */
		serviceCallableUtil.setOperType(operType);
		serviceCallableUtil.setParamsMap(paramsMap);
		
		/* 启动多线程 */
		ExecutorServiceUtil.submit(serviceCallableUtil);
		//requestFaceBookResult(totalNum,currentNum,dataRequestArr);
		// ConstatFinalUtil.SYS_LOGGER.info("resultJSON===={}",resultJSON.toJSONString());
		return path;
	}

	/**
	 * 向服务器请求,把结果上传
	 * @param jsonarr	请求体的数据
	 */
	public void requestFaceBookResult(int totalNum,int currentNum,JSONArray dataArr)
	{
		if(dataArr.size() == 0 )
		{
			ConstatFinalUtil.SYS_LOGGER.info("木有数据:总条数:{},当前条数:{},",totalNum,currentNum);
			/* 木有数据,就不用直接上传 */
			return ;
		}
		/* 当前请求的信息 */
		ConstatFinalUtil.SYS_LOGGER.info("请求服务器--总条数:{},当前条数:{}",totalNum,currentNum);
		// 给接口传数据的准备
		JSONObject dataReqJSON = new JSONObject();
		dataReqJSON = new JSONObject();
		dataReqJSON.put("version", "1");
		dataReqJSON.put("method", "batchInsert");
		dataReqJSON.put("pubKey", "1");
		dataReqJSON.put("encrypt", "1");
				
		/* 请求体 */
		Map<String, String> paramsMap = new HashMap<String, String>();
		/* 请求头 */
		Map<String, String> headerMap = new HashMap<String, String>();
		/* 响应体 */
		Map<String, String> responseMap = new HashMap<String, String>();
		String urlStr = ConstatFinalUtil.CONFIG_JSON.getString("spliderServer.outer.url");
		int totalCount = 0 ; 
		while(true) 
		{
			try
			{
				totalCount ++ ; 
				/* 长期:每次请求都要结果,就是把服务器搞慢 */
				dataReqJSON.put("data", dataArr);
				String  urlDataJson =  URLEncoder.encode(dataReqJSON.toJSONString(),"UTF-8");
				paramsMap.put("json", urlDataJson);
				/* 请求时间加长 */
				headerMap.put(ConstatFinalUtil.REQ_HEADER_IGNORE + "read_timeout", 60 * 5 * ConstatFinalUtil.SECOND + "");
				headerMap.put(ConstatFinalUtil.REQ_HEADER_IGNORE + "req_connect_timeout", 60 * 5 * ConstatFinalUtil.SECOND + "");
				/* 请求一次不重试 */
				headerMap.put("retry", "false");
				/* 请求服务器 */
				String response = this.httpUtil.methodPost(urlStr, headerMap, paramsMap, responseMap);
				JSONObject responseJSON = JSON.parseObject(response);
				if(responseJSON != null && "0".equalsIgnoreCase(responseJSON.getString("code")))
				{
					ConstatFinalUtil.SYS_LOGGER.info("请求结束--总条数:{},当前条数:{},请求次数:{},请求结束:{}",totalNum,currentNum,
							totalCount,dataReqJSON.toJSONString());
					/* 请求成功的时候,清空数据 */
					dataArr.clear();
					break ; 
				}
				/* 休眠1分钟 */
				Thread.sleep(ConstatFinalUtil.SECOND * 60);
			} catch (Exception e)
			{
				ConstatFinalUtil.SYS_LOGGER.info("更新请求结果异常:条数:{},url:{},header:{},{}",dataArr.size() , headerMap,dataReqJSON.toJSONString(),e);
			}
		}
	}

	@Override
	public void writeConfig(JSONObject jsonData)
	{
		String name = jsonData.getString("name");
		String oldName = jsonData.getString("oldName");
		String status = jsonData.getString("status");
		String path = jsonData.getString("path");
		String relaPath = jsonData.getString("relaPath");
		ISystemService systemService = new SystemServiceImpl();
		ASysHistory sysHistory = new ASysHistory();
		sysHistory.setName(name);
		sysHistory.setOldName(oldName);
		sysHistory.setAbsPath(path);
		sysHistory.setRelaPath(relaPath);
		sysHistory.setStatus(Byte.valueOf(status));
		systemService.saveOneHistoryService(sysHistory);
	}
}
